<?php require_once('inc_admin.php'); ?>

	        <!--PAGE CONTENT -->
	        <div id="content">

	            <div class="inner" style="min-height:1200px;">
	                <div class="row">
	                    <div class="col-lg-12">


<?php 
   require_once('inc_admin.php');
    connect();
    $sql='select tid,typename from videotype ';
    //echo $sql.'<br/>';
    if($_REQUEST['key'])
    {
        $key=trim($_REQUEST['key']);
        $sql.="where typename like '%{$key}%'";    
    }
    $result=mysql_query($sql);
    $totalrows=mysql_num_rows($result);
    //获取指定的页码
    $page=$_REQUEST['page'];
    if(!isset($page))
        $page=1;
    if($_POST['search'])
        $page=1;
    //定义每页显示的行数
    $rowsperpage=4;
    //计算从表第几行开始输出
    $start=($page-1)*$rowsperpage;
    $sql.="limit {$start},{$rowsperpage}";
    $result=mysql_query($sql) or die('查询失败！'.mysql_error());
     ?>
   <center> <h3 style="margin-right: 20px">视频类别列表</h3></center>
   <table align="center" class="table table-hover table-condensed">
   <tr class="success">
     <td align="left">
       <form  method=post action="">
         请输入类别名称：
         <input type="text"  class="btn btn-default"name="key">
         <input type="submit" class="btn btn-primary" name="search" value="搜索">
       </form>
     </td>
   </tr>
     </table> 
     <table align="center" class="table table-hover table-condensed" >
     <tr class="success">
    <th>序号</th>
    <th>视频类别名称</th>
    <th>操作</th>
     </tr>
       <?php 
        while ($row=mysql_fetch_assoc($result)) {
          echo '<tr>';
    echo '<td>'.$row['tid'].'</td>';
    echo '<td>'.$row['typename'].'</td>';
    
    
        echo '<td> <a href="typeEditForm.php?id='.$row['tid'].'">修改</a>
        <a href="typeDelete.php?id='.$row['tid'].'"onClick="return confirm(\'确定要删除吗？\');">删除</a></td>';

    echo '</tr>';
  } 
  echo '</table>';
  
  if ($rowsperpage>=$totalrows) 
      $totalpages=1;
   else{
     $totalpages=ceil($totalrows/$rowsperpage);
  }
  //如果不是第一页，则显示第一页和上一页的超链接，否则只显示文字
  //echo '<nav><u1 class="pager">';
  if ($page>1) {
    $first="<a href=?page=1&key={$key}>首页</a>";
    $pre="<a href=?page=".($page-1)."&key={$key}>上一页</a>";
  }else{
    $first='首页';
    $pre='上一页';
 }
 //如果不是最后一页，则显示下一页和最后一页的超链接，否则只显示文字
  if ($page<$totalpages) {
    $last="<a href=?page=$totalpages&key={$key}>尾页</a>";
    $next="<a href=?page=".($page+1)."&key={$key}>下一页</a>";
  }else{
    $last='尾页';
    $next='下一页';
  }
  echo "<table align='center'><tr>";
  echo "<td>共{$totalrows}类视频</td>";
  echo "<td>$first"."&nbsp;&nbsp;"."$pre"."&nbsp;&nbsp;";
  for($i=1;$i<=$totalpages;$i++){
    echo "<a href='?page=$i&key={$key}'>第{$i}页</a>&nbsp;&nbsp;";
  }
  echo "$next"."&nbsp;&nbsp;"."$last&nbsp;";
  //输出第几页/共几页
  echo "<font color=red>";
  echo "第".$page."页/共".$totalpages."页";
  echo "</font></td>";
  //输出转到几页的表单
  ?>
  <td >
    <form  method=post action="">
      <input type="text"  class="btn btn-default"name="page" placeholder="" size=2>
      <input type="submit"  class="btn btn-primary"value="转到">
    </form>
  </td>
                                                                                                                                    
      
     </table>
	   

	                    </div>
	                </div>
              </div>
               </div>
     
	   <!-- FOOTER -->
	    <div id="footer">
	       
	    </div>
	    <!--END FOOTER -->
	     <!-- GLOBAL SCRIPTS -->
	    <script src="assets/plugins/jquery-2.0.3.min.js"></script>
	     <script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
	    <script src="assets/plugins/modernizr-2.6.2-respond-1.1.0.min.js"></script>
	    <!-- END GLOBAL SCRIPTS -->
